home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Games / Strategy / Puzzle / GameMaster / GM Dev Kit / Pascal Units / GraphSubs.unit < prev    next >
Encoding:
Text File  |  1991-12-05  |  2.9 KB  |  115 lines  |  [TEXT/PJMM]

  1. unit GraphSubs;
  2.  
  3. { bits are ©1991 Quinn "The Eskimo", but not all of it}
  4.  
  5. interface
  6.  
  7.     procedure ScaleRect (r1, r2: Rect; numer, denom: integer; var r3: rect);
  8.     procedure ZoomRect (srcrect, dstrect: Rect; var pat: Pattern);
  9.     function CentreString (r: rect; s: str255): point;
  10.     function GetMenuFlash: integer;
  11.     procedure CentreRect (inrect: rect; var centrect: rect);
  12.  
  13.     procedure PlotSICN (r: rect; sicnList: Handle; index: longint);
  14.  
  15. implementation
  16.  
  17.     procedure ScaleRect (r1, r2: Rect; numer, denom: integer; var r3: rect);
  18.         procedure doit (p1, p2: integer; var p3: integer);
  19.         begin
  20.             p3 := p1 + ((p2 - p1) * numer) div denom;
  21.         end; { doit }
  22.     begin
  23.         doit(r1.top, r2.top, r3.top);
  24.         doit(r1.left, r2.left, r3.left);
  25.         doit(r1.bottom, r2.bottom, r3.bottom);
  26.         doit(r1.right, r2.right, r3.right);
  27.     end; { ScaleRect }
  28.  
  29.     procedure ZoomRect (srcrect, dstrect: Rect; var pat: Pattern);
  30.         const
  31.             kZoomMax = 10;
  32.             kDelay = 4;
  33.         var
  34.             junk: longint;
  35.             i: integer;
  36.             ps: PenState;
  37.             r: rect;
  38.     begin
  39.         GetPenState(ps);
  40.         PenNormal;
  41.         PenMode(patXor);
  42.         PenPat(pat);
  43.         r := srcrect;
  44.         FrameRect(r);
  45.         Delay(kDelay, junk);
  46.         for i := 1 to kZoomMax do begin
  47.             FrameRect(r);
  48.             ScaleRect(srcrect, dstrect, i, kZoomMax, r);
  49.             FrameRect(r);
  50.             Delay(kDelay, junk);
  51.         end; { for }
  52.         Delay(kDelay, junk);
  53.         FrameRect(r);
  54.         SetPenState(ps);
  55.     end; { ZoomRect }
  56.  
  57.     function CentreString (r: rect; s: str255): point;
  58.         var
  59.             finfo: fontInfo;
  60.             h, w: integer;
  61.             p: point;
  62.     begin
  63.         GetFontInfo(finfo);
  64.         h := finfo.ascent + finfo.descent;
  65.         w := StringWidth(s);
  66.         p.v := r.top + ((r.bottom - r.top - h) div 2) + finfo.ascent;
  67.         p.h := r.left + ((r.right - r.left - w) div 2);
  68.         CentreString := p;
  69.     end;
  70.  
  71.     procedure CentreRect (inrect: rect; var centrect: rect);
  72.         var
  73.             centwidth, centheight: integer;
  74.             inwidth, inheight: integer;
  75.     begin
  76.         centwidth := centrect.right - centrect.left;
  77.         centheight := centrect.bottom - centrect.top;
  78.         inwidth := inrect.right - inrect.left;
  79.         inheight := inrect.bottom - inrect.top;
  80.         OffsetRect(centrect, -centrect.left + inrect.left, -centrect.top + inrect.top);
  81.         OffsetRect(centrect, (inwidth - centwidth) div 2, (inheight - centheight) div 2);
  82.     end;
  83.  
  84.     function GetMenuFlash: integer;
  85.         type
  86.             intPtr = ^integer;
  87.         const
  88.             MenuFlash = $A24;
  89.     begin
  90.         GetMenuFlash := intPtr(MenuFlash)^;
  91.     end; { GetMenuFlash }
  92.  
  93.     procedure PlotSICN (r: rect; sicnList: Handle; index: longint);
  94.         type
  95.             SICNdata = array[0..1000] of array[1..16] of integer;
  96.             SICNptr = ^SICNdata;
  97.             SICNhand = ^SICNptr;
  98.         var
  99.             state: byte;
  100.             srcBits: BitMap;
  101.             port: GrafPtr;
  102.             sic: SICNhand;
  103.     begin
  104.         state := HGetState(sicnList);
  105.         HLock(sicnList);
  106.         sic := SICNhand(sicnList);
  107.         srcBits.baseAddr := Ptr(@sic^^[index]);
  108.         srcBits.rowBytes := 2;
  109.         SetRect(srcBits.bounds, 0, 0, 16, 16);
  110.         GetPort(port);
  111.         CopyBits(srcBits, port^.portBits, srcBits.bounds, r, srcCopy, nil);
  112.         HSetState(sicnList, state);
  113.     end; { PlotSICN }
  114.  
  115. end. { GraphSubs }